package com.briup.service.impl;

import com.briup.annotation.SystemLog;
import com.briup.bean.EsUser;
import com.briup.exception.BookStoreException;
import com.briup.mapper.EsUserMapper;
import com.briup.service.UserService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * @author pgc
 * @Description:
 * @date 2023/11/12 14:59
 */
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    EsUserMapper mEsUserMapper;
    @SystemLog(businessName = "新增用户")
    @Override
    public void register(EsUser esUser) {
//判断用户名是否为空
        if (!StringUtils.hasText(esUser.getUsername())) {
            throw new
                    BookStoreException(BookStoreException.CodeMsgEnum.USER_USERNAME_IS_NOT_NULL);
        }
        //判断密码是否为空
        if (!StringUtils.hasText(esUser.getPassword())) {
            throw new
                    BookStoreException(BookStoreException.CodeMsgEnum.USER_PASSWORD_IS_NOT_NULL);
        }

        esUser.setRoleId(2);
//执行新增用户操作
        mEsUserMapper.insert(esUser);
    }
    @SystemLog(businessName = "根据用户ID获取用户信息")
    @Override
    public EsUser getUserInfo(Long id) {
        EsUser esUser = mEsUserMapper.selectByPrimaryKey(id);
        return esUser;
    }
}
